<?php

use Phinx\Db\Adapter\MysqlAdapter;
use think\migration\Migrator;
use think\migration\db\Column;

class OrderTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('order');
        $table->addColumn('user_id','integer',array('limit' => MysqlAdapter::INT_REGULAR, 'comment' => '用户id'))->addIndex('user_id');
        $table->addColumn('store_id','integer',array('limit' => MysqlAdapter::INT_REGULAR, 'comment' => '店铺id','default' => 0))->addIndex('store_id');
        $table->addColumn('order_no','string',array('limit' => 100, 'comment' => '订单编号'))->addIndex('order_no',array('unique' => true));
        $table->addColumn('goods_id','biginteger',array('limit' => 20, 'comment' => '商品id','default' => 0));
        $table->addColumn('order_type','boolean',array('limit' => 1, 'default' => 1,'comment' => '订单类型'));
        $table->addColumn('payment_type','boolean',array('limit' => 1,'default' => 1, 'comment' => '交易类型'));
        $table->addColumn('discount_amount','decimal',array('precision'=> 10,'scale'=> 2, 'default' => 0, 'comment' => '订单优惠金额'));
        $table->addColumn('real_amount','decimal',array('precision'=> 10,'scale'=> 2, 'default' => 0, 'comment' => '订单实付金额'));
        $table->addColumn('receiver_name','string',array('limit' => 30, 'default' => '', 'comment' => '收货人姓名'));
        $table->addColumn('receiver_phone','char',array('limit' => 11, 'default' => '', 'comment' => '收货人手机号'));
        $table->addColumn('receiver_province','string',array('limit' => 30, 'default' => '', 'comment' => '收货人所在省份'));
        $table->addColumn('receiver_city','string',array('limit' => 30, 'default' => '', 'comment' => '收货人所在城市'));
        $table->addColumn('receiver_county','string',array('limit' => 30, 'default' => '', 'comment' => '收货人所在县'));
        $table->addColumn('receiver_address','string',array('limit' => 80, 'default' => '', 'comment' => '收货人所在详细地址'));
        $table->addColumn('remark','string',array('limit' => 255, 'default' => '', 'comment' => '订单备注'));
        $table->addColumn('status','boolean',array('limit' => 1, 'comment' => '订单状态 -1 已取消 0 待付款 1 待发货 2 待收货 3 待评价 4 已完成 5 申请退款 6 退款完成 '));
        $table->addTimestamps('create_time','update_time');
        $table->create();
    }
}
